package com.example.util;

import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

public class RoundRobinList<T>{

    private final List<T> items;

    private final AtomicInteger index;

    public RoundRobinList(List<T> items) {
        if (items == null || items.isEmpty()) {
            throw new IllegalArgumentException("List cannot be null or empty");
        }
        this.items = items;
        this.index = new AtomicInteger(0);
    }

    /**
     * 获取下一个元素
     *
     * @return 下一个元素
     */
    public T next() {
        int currentIndex = index.getAndUpdate(i -> (i + 1) % items.size());
        return items.get(currentIndex);
    }


}
